# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=python-logfury
pkgver=1.0.1
pkgrel=4
pkgdesc='Low boilerplate logging of Python method calls'
arch=('any')
url='https://github.com/reef-technologies/logfury'
license=('BSD')
depends=('python')
makedepends=(
  'git'
  'python-build'
  'python-installer'
  'python-setuptools'
  'python-setuptools-scm'
  'python-wheel'
)
checkdepends=(
  'python-pytest'
  'python-testfixtures'
)
_commit='78687dd422cb77d365a36e5d047d0c71a11065d0'
source=(
  "$pkgname::git+$url#commit=$_commit"
  'remove-version-constraint.patch'
)
b2sums=('SKIP'
        'c641e732d6bfc82c0494c5e5362e1d875bb7b78df865f2330853693ba1985ffc35593efbcb268d747cbc3aba8344360616b71ab0b2eea11c51f10ee770358d44')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  patch -p1 -i "$srcdir/remove-version-constraint.patch"
}

build() {
  cd "$pkgname"

  SETUPTOOLS_SCM_PRETEND_VERSION="$pkgver" python -m build --wheel --no-isolation 
}

check() {
  cd "$pkgname"

  pytest -v
}

package() {
  cd "$pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl

  # symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir/usr/share/licenses/$pkgname"
  ln -s "$site_packages/${pkgname#python-}-$pkgver.dist-info/LICENSE" \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
